package member.base.service;

import m.common.model.util.ModelQueryList;
import m.common.service.Service;
import m.system.util.NumberUtil;
import member.base.model.MemberInfo;

public class MemberInfoService extends Service {

    public MemberInfo get(String oid) throws Exception {
        return ModelQueryList.getModel(MemberInfo.class,oid,"*","level.*");
    }
    /**
     * 更新冻结金额
     */
    public void updateFreeze(String oid,Double payAmount) throws Exception {
        MemberInfo member= getModel(MemberInfo.class,oid,"*");
        member.setFreeze(NumberUtil.round(member.getFreeze()+payAmount));
        updateModel(member,"freeze");
    }

    /**
     * 更新金额和积分
     */
    public void updateAmount(String oid,Double realMoney,Double giveMoney,Integer point) throws Exception {
        MemberInfo member= getModel(MemberInfo.class,oid,"*");
        member.setRealMoney(NumberUtil.round(member.getRealMoney()+realMoney));
        member.setGiveMoney(NumberUtil.round(member.getGiveMoney()+giveMoney));
        member.setBalance(NumberUtil.round(member.getRealMoney()+member.getGiveMoney()));
        member.setPoint(member.getPoint()+point);
        updateModel(member,"realMoney","giveMoney","balance","point");
    }

    /**
     * 添加订单数和已使用金额
     */
    public void addOrderAndUpdateAmount(String oid,Double payAmount,Double realMoney,Double giveMoney,Integer point) throws Exception {
        MemberInfo member= getModel(MemberInfo.class,oid,"*");
        member.setOrderNum(member.getOrderNum()+1);
        member.setUseMoney(NumberUtil.round(member.getUseMoney()+payAmount));
        member.setRealMoney(NumberUtil.round(member.getRealMoney()+realMoney));
        member.setGiveMoney(NumberUtil.round(member.getGiveMoney()+giveMoney));
        member.setBalance(NumberUtil.round(member.getRealMoney()+member.getGiveMoney()));
        member.setPoint(member.getPoint()+point);
        updateModel(member,"orderNum","useMoney","realMoney","giveMoney","balance","point");
    }
}
